﻿<UserControl x:Class="XamlTorrent.Managers.MonoTorrent.UI.CreateTorrentTask"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <UserControl.Resources>
        <Style x:Key="CollapseOnNullTorrent" TargetType="{x:Type FrameworkElement}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=LoadedTorrent}" Value="{x:Null}">
                    <Setter Property="Visibility" Value="Collapsed" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="VisibleOnNullTorrent" TargetType="{x:Type FrameworkElement}">
            <Setter Property="Visibility" Value="Collapsed" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=LoadedTorrent}" Value="{x:Null}">
                    <Setter Property="Visibility" Value="Visible" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Label Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" Target="{Binding ElementName=torrentUri}">Torrent File</Label>
        <TextBox Name="torrentUri" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch" LostFocus="torrentUri_LostFocus" />
        <Label Grid.Row="1" HorizontalAlignment="Right">Save To</Label>
        <DockPanel Grid.Row="1" Grid.Column="1">
            <Button DockPanel.Dock="Right" TabIndex="1">
                <TextBlock Margin="5,0,5,0">...</TextBlock>
            </Button>
            <TextBox Name="saveLocation" HorizontalAlignment="Stretch" TabIndex="0" />
        </DockPanel>
        <GroupBox  Grid.Row="2" Grid.ColumnSpan="2" Header="Torrent Contents">
            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
                <TextBlock Style="{StaticResource VisibleOnNullTorrent}">
                    Torrent file not loaded, enter a file path or URL to a torrent file.
                </TextBlock>
                <Grid Style="{StaticResource CollapseOnNullTorrent}" 
                      DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=LoadedTorrent}">
                    <Grid.Resources>
                        <Style TargetType="TextBlock">
                            <Setter Property="VerticalAlignment" Value="Center" />
                        </Style>
                    </Grid.Resources>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Label Grid.Row="0" HorizontalAlignment="Right">Name:</Label>
                    <TextBlock Grid.Row="0" Grid.Column="1" Width="300" HorizontalAlignment="Left" Text="{Binding Path=Name}" />
                    <Label Grid.Row="1" HorizontalAlignment="Right">Size:</Label>
                    <TextBlock Grid.Row="1" Grid.Column="1" Width="300" HorizontalAlignment="Left" Text="{Binding Path=Size}" />
                    <Label Grid.Row="2" HorizontalAlignment="Right">Comment:</Label>
                    <TextBlock Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding Path=Comment}" />
                    <Expander Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" VerticalAlignment="Stretch">
                        <Expander.Header>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Files (" />
                                <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Path=SelectedFilesCount}" />
                                <TextBlock Text="/" />
                                <TextBlock Text="{Binding Path=Files.Length}" />
                                <TextBlock Text=" selected)" />
                            </StackPanel>
                        </Expander.Header>
                        <DockPanel>
                            <Grid DockPanel.Dock="Top">
                                <Grid.Resources>
                                    <Style TargetType="GridSplitter">
                                        <Setter Property="Width" Value="3" />
                                        <Setter Property="Background" Value="Blue" />
                                    </Style>
                                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1" x:Key="headerBrush">
                                        <GradientStop Color="{x:Static SystemColors.ControlColor}" Offset="0" />
                                        <GradientStop Color="{x:Static SystemColors.ControlDarkColor}" Offset="1" />
                                    </LinearGradientBrush>
                                    <Style TargetType="TextBlock">
                                        <Setter Property="Background" Value="{StaticResource headerBrush}" />
                                        <Setter Property="HorizontalAlignment" Value="Stretch" />
                                    </Style>
                                </Grid.Resources>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                </Grid.ColumnDefinitions>
                                <TextBlock Name="fileNameHeader" Text="Name" Grid.Column="0" />
                                <GridSplitter  Grid.Column="1" HorizontalAlignment="Left" />
                                <TextBlock Name="fileSizeHeader" Text="Size" Grid.Column="2" />
                                <GridSplitter  Grid.Column="3" HorizontalAlignment="Left" />
                            </Grid>
                            <ItemsControl ItemsSource="{Binding Path=Files}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <CheckBox Content="{Binding Path=Path}" Width="{Binding ElementName=fileNameHeader, Path=ActualWidth}" IsChecked="True" Checked="FileCheckBox_CheckedChanged" Unchecked="FileCheckBox_CheckedChanged" />
                                            <TextBlock Text="{Binding Path=Length}" Width="{Binding ElementName=fileSizeHeader, Path=ActualWidth}" />
                                        </StackPanel>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </DockPanel>
                    </Expander>
                </Grid>
            </StackPanel>
        </GroupBox>
    </Grid>
</UserControl>
